<!DOCTYPE html>
<html>
<head>
    {include file="Public:header"}
</head>
<body class="white-bg" style="padding: 3px">
<div class="page-heade">
    <h2 class="title_color text-center">添加新用户</h2>
</div>
<form action="">
<div class="padding-10">
    <table class="table table-striped table-bordered table-hover bud_hei text-center" id="editable">
        <tr>
            <td class="text-right">用户名<font color="red">*</font>:</td>
            <td class="text-left">
                {if isset($data)&&$data.login_name}
                {$data.login_name}
                {else}
                <input type="text" class="form-control" name="login_name" value=""><bold>（名称不能重复）</bold>
                {/if}
            </td>
        </tr>
        <tr>
            <td class="text-right">密码:</td>
            <td class="text-left">系统默认初始密码请联系管理员，修改密码请到用户管理主界面</td>
        </tr>
        <tr>
            <td class="text-right">对应职员<font color="red">*</font>:</td>
            <td class="text-left">
                <div style="float:left;">
                    <div class="input-group" id="employee_input"  {if isset($data)}style="display: none;"{/if}>
                        <input type="text" class="form-control" id="employee" placeholder="请输入关键字或空格查询">
                        <div class="input-group-btn">
                            <ul class="dropdown-menu dropdown-menu-right" role="menu">
                            </ul>
                        </div>
                    </div>
                    <div id="employee_queding" class="selectedOnlyOne" {if !isset($data)}style="display: none;"{/if}>
                        <input type="hidden" name="employee_id" value="{if isset($data)}{$data.employee_id}{/if}">
                        <span class="inin">{if isset($data)}{$data.em_name}{/if}</span>
                        <span class="close">×</span>
                    </div>
                </div>
                <a href="javascript:;" style="float:left;line-height:30px;" id="select_employee" class="btn btn-outline btn-default">选择</a>
            </td>
        </tr>
        <tr>
            <td class="text-right">用户类型:</td>
            <td class="text-left">
                <label for=""><input type="radio" name="type" value="2" {if isset($data)&&$data.type==2}checked{/if}>超级用户</label>
                <label for=""><input type="radio" name="type" value="1" {if (isset($data)&&$data.type==1)||!isset($data)}checked{/if}>一般用户</label>
            </td>
        </tr>
        <tr>
            <td class="text-right">状态:</td>
            <td class="text-left">
                <label for=""><input type="radio" name="state" value="0" {if isset($data)&&$data.state==0}checked{/if}>冻结</label>
                <label for=""><input type="radio" name="state" value="1" {if (isset($data)&&$data.state==1)||!isset($data)}checked{/if}>正常</label>
            </td>
        </tr>
        <tr>
            <td class="text-right">是否允许通过移动终端登录:</td>
            <td class="text-left">
                <label for=""><input type="radio" name="power" value="1" {if (isset($data)&&$data.power==1)||!isset($data)}checked{/if}>是</label>
                <label for=""><input type="radio" name="power" value="0" {if isset($data)&&$data.power==0}checked{/if}>否</label>
            </td>
        </tr>
        <tr>
            <td class="text-right"></td>
            <td class="text-left">
                <input type="button" value="提交" id="tijiao">
                <input type="button" value="返回" id="fanhui">
            </td>
        </tr>
    </table>
</div>
</form>
</body>
</html>
{include file="Public:footer"}
<script src="__STATIC__/layout/js/plugins/suggest/bootstrap-suggest.min.js"></script>
<script>
$(function () {
    $('#fanhui').on('click',function () {

        location.href='{:url("manage")}'
    })
    $('#tijiao').on('click',function () {
        $.post('',$(this).closest('form').serialize(),function (data) {
            if(data.success){
                swal({title:data.msg},function () {
                    location.href='{:url("manage")}'
                })
            }else{
                swal('',data.msg,'error')
            }
        },'json')
        return false
    })

    //职员
    $("#employee").bsSuggest({
        url: '{:url("bsemployee")}',
        effectiveFields: ["id", "em_name"],
        searchFields: [ "em_name"],
        effectiveFieldsAlias: {em_name: "姓名"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "em_name",
        clearable: true
    }).on('onDataRequestSuccess', function (e, result) {

        console.log('onDataRequestSuccess: ', result);
    }).on('onSetSelectValue', function (e, keyword) {
        $('#employee_queding').find('.inin').html(keyword.key)
        $('#employee_queding').find('.inin').data('id',keyword.id)
        $('#employee_queding').show()
        $('#employee_input').hide()
        $('#employee_queding').find('input').val(keyword.id)

    });

    //关闭销售人员
    $('.selectedOnlyOne .close').on('click',function () {
        $('#employee_queding').hide()
        $('#employee_queding input').val('')
        $('#employee_queding .inin').html('')
        $('#employee_input').show()
        $('#employee_input').find('input').val('')
        return false
    })

    //选择销售人员
    $('#select_employee').on('click',function(){
        layer.open({
            type: 2,
            title: '&nbsp;',
            shadeClose: true,
            shade: false,
            maxmin: true, //开启最大化最小化按钮
            area: ['800px', '500px'],
            content: '{:url("open/employee2")}',
            btn:['确定','关闭'],
            yes:function (i,o) {
                var a = $(o).find('iframe').contents()

                var id =  a.find("#renyuan").val();
                var name =  a.find("#renyuanname").val();
                if(id){
                    var jxs_queding = $('#employee_queding')
                    var jxs_input = $('#employee_input')

                    jxs_queding.find('.inin').html(name)
                    jxs_queding.show()
                    jxs_queding.find('input').val(id)
                    jxs_input.hide()
                }

                layer.close(i)
            }
        })
        return false
    })
})
</script>